Description:
SEB detects statements with empty bodies such as empty synchronized
(locked in C#) statements and finally blocks.
These constructs may signal that some functionality should have been implemented
but is missing. Otherwise, empty statements can be safely removed.
When the option Check catch clauses is set in the audit's properties, SEB also looks for empty
catch blocks. Often in these cases, you should add error-handling code.
When the option Check loop bodies is set, SEB looks for empty
bodies inside of for, while, and do loops.
It is suggested to avoid this programming style.
When the option Check method bodies is set, SEB looks for empty
bodies of non-virtual methods.
Incorrect:
try {
IResource resource = acquireResource(resourceName);
...
} catch (ResourceNotFoundException e) {
} finally {
}
Correct:
try {
IResource resource = acquireResource(resourceName);
...
} catch (ResourceNotFoundException e) {
// handle exception
...
}
Incorrect:
for (XmlNode n = node.FirstChild; n != null && n.LocalName != name; n = n.NextSibling);
Correct:
for (XmlNode n = node.FirstChild; n != null; n = n.NextSibling) {
if (n.LocalName == name) {
break;
}
}